#include <astree/xabstractsynatxtreeblock.h>

XAbstractSyntaxTreeBlock::XAbstractSyntaxTreeBlock(XTokenPtr inputToken):
    XAbstractSyntaxTree(inputToken) {
    setName(L"block");
}

bool XAbstractSyntaxTreeBlock::invoke(std::shared_ptr<XVariableTable> table) {
    for (auto child : children) {
        if (!child->invoke(table))
            return false;

        if (child->shouldBreak()) {
            invokeBreak = true;
            return true;
        } else if (child->shouldReturn()) {
            result = child->getResult();
            invokeReturn = true;
            return true;
        }
    }
    return true;
}
